<?php

/* Portal Pracy - praca magisterska
 * autor: Tomek Ceszke
 * email: tomek.ceszke@gmail.com
 * Politechnika Koszalińska 2007
 */

class TagsController extends AppController
{
	var $name = 'Tags';
	var $uses = array('Tag','Ad');

	function getNames()
	{
		$this->autoRender = false;

		$tmpData = $this->Tag->query('SELECT tags.name, ads_tags.ad_id, count(ads_tags.tag_id) as count FROM ads_tags, tags WHERE tags.id = ads_tags.tag_id group by ads_tags.tag_id order by count DESC LIMIT 20');

		$i = 0;

		foreach ($tmpData as $tmpItem) {
				
			$defCriteria = aa(
			"Ad.public_date", "<= ".date('Y-m-d'),
			"Ad.validity_date", "> ".date('Y-m-d'),
			"Ad.status",'1'
			);
				
			$defCriteria['Ad.id'] = $tmpItem['ads_tags']['ad_id'];
			$cnt = $this->Ad->findCount($defCriteria);
				
			if($cnt<1)
			{
				unset($tmpData[$i]);
			}
				
			$i++;
		}
		return $tmpData;

	}
}
?>